import { ElMessage } from 'element-plus'

export class AppError extends Error {
  constructor(message: string, public code?: string) {
    super(message)
    this.name = 'AppError'
  }
}

export function handleError(error: unknown) {
  console.error('Error:', error)
  
  if (error instanceof AppError) {
    ElMessage.error(error.message)
  } else if (error instanceof Error) {
    ElMessage.error('系统错误：' + error.message)
  } else {
    ElMessage.error('未知错误')
  }
}

export function handleSuccess(message: string) {
  ElMessage.success(message)
} 